package com.ruoyi.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.CardMemberInfo;
import com.ruoyi.system.service.ICardMemberInfoService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 会员信息Controller
 *
 * @author ruoyi
 * @date 2025-01-25
 */
@RestController
@RequestMapping("/system/info")
public class CardMemberInfoController extends BaseController
{
    @Autowired
    private ICardMemberInfoService cardMemberInfoService;

    /**
     * 查询会员信息列表
     */
    @PreAuthorize("@ss.hasPermi('system:info:list')")
    @GetMapping("/list")
    public TableDataInfo list(CardMemberInfo cardMemberInfo)
    {
        startPage();
        List<CardMemberInfo> list = cardMemberInfoService.selectCardMemberInfoList(cardMemberInfo);
        return getDataTable(list);
    }

    /**
     * 导出会员信息列表
     */
    @PreAuthorize("@ss.hasPermi('system:info:export')")
    @Log(title = "会员信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CardMemberInfo cardMemberInfo)
    {
        List<CardMemberInfo> list = cardMemberInfoService.selectCardMemberInfoList(cardMemberInfo);
        ExcelUtil<CardMemberInfo> util = new ExcelUtil<CardMemberInfo>(CardMemberInfo.class);
        util.exportExcel(response, list, "会员信息数据");
    }

    /**
     * 获取会员信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:info:query')")
    @GetMapping(value = "/{cardId}")
    public AjaxResult getInfo(@PathVariable("cardId") Long cardId)
    {
        return success(cardMemberInfoService.selectCardMemberInfoByCardId(cardId));
    }

    /**
     * 新增会员信息
     */
    @PreAuthorize("@ss.hasPermi('system:info:add')")
    @Log(title = "会员信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CardMemberInfo cardMemberInfo)
    {
        return toAjax(cardMemberInfoService.insertCardMemberInfo(cardMemberInfo));
    }

    /**
     * 修改会员信息
     */
    @PreAuthorize("@ss.hasPermi('system:info:edit')")
    @Log(title = "会员信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CardMemberInfo cardMemberInfo)
    {
        return toAjax(cardMemberInfoService.updateCardMemberInfo(cardMemberInfo));
    }

    /**
     * 删除会员信息
     */
    @PreAuthorize("@ss.hasPermi('system:info:remove')")
    @Log(title = "会员信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{cardIds}")
    public AjaxResult remove(@PathVariable Long[] cardIds)
    {
        return toAjax(cardMemberInfoService.deleteCardMemberInfoByCardIds(cardIds));
    }

    /**
     * 修改会员信息
     */
    @PreAuthorize("@ss.hasPermi('system:info:edit')")
    @Log(title = "卡片状态信息", businessType = BusinessType.UPDATE)
    @GetMapping("/updateCardType/{cardIds}/{cardType}")
    public AjaxResult updateCardType(@PathVariable Long[] cardIds, @PathVariable String cardType)
    {
        return toAjax(cardMemberInfoService.updateCardMemberInfoByCardIds(cardIds, cardType));
    }
}
